//go:generate ldetool log.txt
package fex

import (
	"bytes"
	"io"
)

type trace struct {
	AppName []byte
	Trace   []byte
}

func (p *LogParser) unmarshalTrace(tmp []byte) (t trace, err error) {
	t = p.Trace
	if len(tmp) >= 1 && tmp[0] == '[' {
		tmp = tmp[1:]
	} else {
		t.Trace = tmp
		return
	}

	// Take until ',' as AppName(string)
	pos := bytes.IndexByte(tmp, ',')
	if pos >= 0 {
		t.AppName = tmp[:pos]
		tmp = tmp[pos+1:]
	} else {
		err = io.EOF
		return
	}

	// Take until ']' as TraceID(string)
	pos = bytes.IndexByte(tmp, ']')
	if pos >= 0 {
		t.Trace = tmp[:pos]
	} else {
		t.Trace = tmp
	}

	return
}
